package top.mccat.raven.item;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import top.mccat.raven.dao.OnStrengthItem;

import java.util.List;

/**
 * @ClassName: StrengthItem
 * @Description: 基类物品
 * @Author: Raven
 * @Date: 2021/7/7
 * @Version: 1.0
 */
public class StrengthItem implements OnStrengthItem {
    private Material itemMaterial;
    private ItemMeta strengthMeta;
    private ItemStack strengthStack;
    private int level;
    public static final String endLore = "§e--------------------";
    public static final String FULLLEVEL = "✡✡✡✡✡✡✡✡✡✡";
    public StrengthItem(ItemStack stack){
        this.strengthStack = stack;
        strengthMeta = stack.getItemMeta();
        itemMaterial = stack.getType();
    }

    public int getLevel(String startLore){
        if(strengthMeta!=null){
            level = 0;
            List<String> lores = strengthMeta.getLore();
            boolean startCount = false;
            if(lores!=null){
                for(int i=0;i<lores.size();i++){
                    if(lores.get(i).equals(endLore)){
                        startCount = false;
                    }
                    if(startCount){
                        level += lores.get(i).length()-2;
                    }
                    if(lores.get(i).equals(startLore)){
                        startCount = true;
                    }
                }
            }
        }
        return level;
    }

    public void setStrengthStack(ItemStack strengthStack) {
        this.strengthStack = strengthStack;
    }

    public ItemMeta getStrengthMeta() {
        return strengthMeta;
    }

    public Material getItemMaterial() {
        return itemMaterial;
    }

    public ItemStack getStrengthStack() {
        return strengthStack;
    }

    @Override
    public ItemStack getStrengthstack(StrengthItem strengthItem, String color, int level) {
        return null;
    }
}
